/**
 * @param {number[][]} obstacleGrid
 * @return {number}
 */

var uniquePathsWithObstacles = function (obstacleGrid) {
    let row = obstacleGrid.length
    let col = obstacleGrid[0].length
    // 初始化数组
    let res = new Array(row).fill(0)
    for (let i = 0; i < row; i++) {
        res[i] = new Array(col).fill(0)
    }
    // 行 但如果有障碍物 那么后面的都为0
    for (let i = 0; i < row; i++) {
        if (obstacleGrid[i][0] === 1) {
            break
        } else {
            res[i][0] = 1
        }
    }
    // 列 但如果有障碍物 那么后面的都为0
    for (let i = 0; i < col; i++) {
        if (obstacleGrid[0][i] === 1) {
            break
        } else {
            res[0][i] = 1
        }
    }
    // 剩余
    for (let i = 1; i < row; i++) {
        for (let j = 1; j < col; j++) {
            if (obstacleGrid[i][j] === 1) {
                continue
            } else {
                res[i][j] = res[i - 1][j] + res[i][j - 1]
            }
        }
    }
    return res[row - 1][col - 1]
};
uniquePathsWithObstacles([[0, 0]])